/*
 * BBActionMapStart.java
 *
 * Created on March 17, 2008, 6:00 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package hextd.blackBox;

import hextd.util.Context;

/**
 *
 * @author hylke
 */
public class BBActionMapStart implements BBAction {
    
    private static final BlackBox.ActionType type = BlackBox.ActionType.MapStart;
    private int     gameTime;
    private String  map;
    private String  mapMd5;
    private String  version;
    
    /** Creates a new instance of BBActionMapStart */
    public BBActionMapStart(int gameTime, String map, String mapMd5, String version) {
        this.gameTime = gameTime;
        this.map = map;
        this.mapMd5 = mapMd5;
        this.version = version;
    }
    
    @Override
    public BlackBox.ActionType getType() {
        return BBActionMapStart.type;
    }
    
    @Override
    public int getGameTime() {
        return this.gameTime;
    }
    
    @Override
    public void execute(Context c) {
        //System.out.println("BBActionMapStart::execute: "+c.gameTime+" Loading map "+this.map+", version "+this.version);
        if (!c.VERSION.equals(this.version)) {
            System.err.println("BBActionMapStart::execute: Warning recoring made with version "+this.version+"\n but this is version "+c.VERSION+",\n playback may not work as expected!");
            c.showAlert("Warning recoring made with version "+this.version+"\n but this is version "+c.VERSION+",\n playback may not work as expected!");
        }
        if (!c.blackBoxCurrent.startMap(this.map)) {
            System.err.println("BBActionMapStart::execute: Sync error: Loading map failed!");
            c.showAlert("Loading map failed, playback may not work as expected!");
        }
        if (!c.mapMD5.equalsIgnoreCase(this.mapMd5)) {
            System.err.println("BBActionMapStart::execute: Sync error: Map MD5 does not match!");
            c.showAlert("Loaded map is not the same as map used in replay. Playback may not work as expected!");
        }
    }
    
    @Override
    public String getString() {
        return ""+this.gameTime+" L "+this.map+" "+this.mapMd5+" "+this.version+"\n";
    }
}
